package cn.tianyigps.obd;


import cn.tianyigps.obd.channels.TYNioSocketChannel;
import cn.tianyigps.obd.decode.LengthFieldBasedFrameDecoder;
import cn.tianyigps.obd.handler.ChatHeartbeatHandler;
import cn.tianyigps.obd.handler.EquipmentHandler;
import cn.tianyigps.obd.pipelines.TYChannelPipeline;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

public class TcpServerChannelInitalizer extends ChannelInitializer<TYNioSocketChannel> {
    @Override
    public void initChannel(TYNioSocketChannel ch) {
        //处理日志
        TYChannelPipeline pipeline = (TYChannelPipeline) ch.pipeline();
        pipeline.addLast(new LoggingHandler(LogLevel.INFO));
        //处理心跳
        pipeline.addLast(new IdleStateHandler(1800, 0, 1800, TimeUnit.SECONDS));
        pipeline.addLast(new ChatHeartbeatHandler());
//        pipeline.addLast(new EquipmentDecoder());
//         分包器
        pipeline.addLast(new LengthFieldBasedFrameDecoder(65536, 3, 2, 10,0));
        // 解析处理类
        pipeline.addLast(new EquipmentHandler());
    }
}